<?php
/**
 * Smarty plugin
 * @package Smarty
 * @subpackage plugins
 */

/**
 * Smarty {property} function plugin
 *
 * Type:     function<br>
 * Name:     property<br>
 * Input:<br>
 *           - property      (required) - integer, ID of Property list
 *           - assign        (required) - string, variable to which assign result
 *
 * Purpose:  Get array of Properties
 * @author Novachok Alexandr <novachok at ukr dot net>
 * @param array
 * @param Smarty
 * @return array
 */

function smarty_function_property($params, &$smarty)
{
    $property  = null;
    $assign    = null;
    $result    = false;
    $MECCANO   = $GLOBALS['MECCANO'];

    foreach($params as $_key => $_val)
    {
        switch($_key)
        {
            case 'property':
                $$_key = (integer)$_val;
                break;

            case 'assign':
                $$_key = (string)$_val;
                break;
        }
    }

    if($assign != false)
    {
        $result = $MECCANO->GetProperty($property);
    }

    $smarty->assign("$assign", $result);
}